package com.example.r2022913.service.WxService.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.r2022913.model.dao.WxDao.WcDao;
import com.example.r2022913.model.entity.WxEntity.WcEntity;
import com.example.r2022913.service.WxService.WcService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Map;

@Service
public class WcServiceImpl extends ServiceImpl<WcDao, WcEntity> implements WcService {
    @Autowired
    WcDao wcDao;
    @Override
    public IPage wcList(Integer pageNum, Integer pageSize, Map<String, Object> params) {
        QueryWrapper<WcEntity> queryWrapper = new QueryWrapper<>();
        //拿出参数关键字
        String key = (String) params.get("key");
        //模糊查询厕所名称和地点
        if (StringUtils.hasText(key)){
            queryWrapper.like("wc_name",key).or().like("wc_address",key);
        }
        Page pageWc = new Page(pageNum,pageSize);
        IPage<WcEntity> page=this.page(pageWc,queryWrapper);
        return page;
    }

    @Override
    public void delete(Integer id) {
        wcDao.deleteById(id);
    }


    @Override
    public void saveAndUpdate(WcEntity wcEntity){
        this.saveOrUpdate(wcEntity);
    }


}
